package org.feng.config;

import org.feng.common.CustomHandlerMethodReturnValueHandler;
import org.feng.common.RequestHolderInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.method.support.HandlerMethodReturnValueHandler;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.List;

/**
 * MVC配置
 *
 * @version v1.0
 * @author: fengjinsong
 * @date: 2023年08月26日 14时06分
 */
@Configuration
public class WebMvcConfiguration implements WebMvcConfigurer {

    @Bean
    public HandlerInterceptor handlerInterceptor() {
        return new RequestHolderInterceptor();
    }

    @Override
    public void addReturnValueHandlers(List<HandlerMethodReturnValueHandler> returnValueHandlers) {
        returnValueHandlers.add(new CustomHandlerMethodReturnValueHandler());
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(handlerInterceptor()).addPathPatterns("/**");
    }
}
